package com.jic.order.controller.feign;

import com.jic.common.base.vo.RestResult;
import com.jic.order.api.OrderGoodsApi;
import com.jic.order.response.OrderGoodsResponse;
import com.jic.order.service.OrderGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: TODO
 * @author: lixuehui
 * @date: 2020/11/28 15:46
 * @Version 1.0
 */
@Api(tags = {"Feign-top10商品信息"})
@RequestMapping(value = "/feign/orderGoods")
@RestController
public class OrderGoodesFeign implements OrderGoodsApi {

    @Resource
    private OrderGoodsService orderGoodsService;


    @Override
    @PostMapping("/queryTopTenGoodes")
    @ApiOperation(value = "查询当日热销数据")
    public RestResult<List<OrderGoodsResponse>> queryTopTenGoodes() {
        //第一步 查询热销10条数据 获取其Id
        List<OrderGoodsResponse> queryTopTenGoodes = orderGoodsService.queryTopTenGoodes();
        //第二步 将查询出的数据，新增至 m_hot_product商品表

        queryTopTenGoodes.forEach(item ->{
            orderGoodsService.insertProductbyOrder(item);
        });

        return null;
    }



//
//    //定时任务
////    @Scheduled(cron = "1/10 0 0 * * ?")
//    public  void  getTopTenGoods(){
//        //第一步 查询热销10条数据 获取其Id
//        List<OrderGoodsResponse> queryTopTenGoodes = orderGoodsService.queryTopTenGoodes();
//        //第二步 将查询出的数据，新增至 m_hot_product商品表
//        queryTopTenGoodes.forEach(item ->{
//
//            orderGoodsService.insertProductbyOrder(item);
//        });
//        System.out.println("查询top10商品id：" + queryTopTenGoodes);
//    }

}
